<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>零钱兑换II</title>
</head>
<body>
  <!-- 如果求组合数就是外层for循环遍历物品，内层for遍历背包。
  如果求排列数就是外层for遍历背包，内层for循环遍历物品。 -->
  <script>
    function fn(amount, coins) {
      let dp = new Array(amount + 1).fill(0);
      dp[0] = 1;
      for (let i of coins) {
        for (let j = i; j <= amount; j++) {
          dp[j] += dp[j - i];
        }
      }
      return dp[amount];
    }
    console.log(fn(5, [1, 2, 5]))
  </script>
</body>
</html>